﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaleta.Network;
using Kaleta.Network.Serialization.Types;
using System.Diagnostics;

namespace SimpleCharServerClient
{
    /// <summary>
    /// Represents a chatter (person who chats ;)) in a chat application. 
    /// Every chatter can see others chatters and the chatter's message.
    /// </summary>
    public class Chatter: DistributableObject
    {
        public Chatter()
        {
            _message = DistributableProperty<DistributableString>.Register("Message", this, onMessageRecieved);
            _creator = DistributableProperty<DistributableString>.Register("Creator", this);
        }

        private void onMessageRecieved(object sender, PropertyChangedEventArgs<DistributableString> args)
        {
            Debug.WriteLine(DateTime.Now.ToLongTimeString() + " > From server: new message: " + args.NewValue);
            HasNewMessage = true;
        }

        /// <summary>
        /// Message sent by the chatter
        /// </summary>
        [Distribute]
        public DistributableString Message
        {
            get
            {
                return _message.GetValue();
            }
            set
            {
                _message.SetValue(value);
            }
        }
        private DistributableProperty<DistributableString> _message;

        /// <summary>
        /// Name of the chatter
        /// </summary>
        [Distribute]
        public DistributableString Creator
        {
            get
            {
                return _creator.GetValue();
            }
            set
            {
                _creator.SetValue(value);
            }
        }
        private DistributableProperty<DistributableString> _creator;

        /// <summary>
        /// This will indicate whether there is a new message for this chatter, which needs to be displayed.
        /// </summary>
        public bool HasNewMessage = false;
    }
}
